package mware_lib;

import java.util.ArrayList;
import java.util.List;


public class Stub {
    private NameServiceMessage reference;
    private String method = "";
    private List<Class<?>> types = new ArrayList<Class<?>>();
    private List<Object> values = new ArrayList<Object>();

    public String send() {
        String receivedMsg = "";
        StubMessage stubMessage = new StubMessage(reference,method,types.toArray(new Class<?>[types.size()]),values.toArray());
        if (!((this.reference== null) && (this.method.compareTo("") == 0))) {
            Communication comObj = new Communication(reference.getHost(), reference.getPort());
            if(Config.DEBUGGER) System.out.println("Stub send mit stubMessage ");
            receivedMsg = (String)comObj.sendAndReceive(stubMessage);
            if(Config.DEBUGGER) System.out.println("Stub receivedMsg mit: " + receivedMsg);
        } else {
            if(Config.DEBUGGER) System.out.println("Message nicht vollstaendig um zu senden");
        }
        return receivedMsg;
    }

    public void addParameter(Class<?> type, Object value) {
        types.add(type);
        values.add(value);
    }

    public void setReference(NameServiceMessage reference) {
        this.reference = reference;
    }

    public void setMethod(String method) {
        this.method = method;
    }



}
